import Vue from 'vue'
import {login} from "@/api/user"


const user={
    state: {
        token:"",
        name:"",
        welcome:"",
        avatar:"",
        info:{}
    },
    mutations: {
        SET_TOKEN:(state,token)=>{
            state.token=token
        },
        SET_NAME:(state,{name,welcome})=>{
            state.name=name,
            state.welcome=welcome
        },
        SET_AVATAR:(state,avatar)=>{
            state.avatar=avatar
        },
        SET_INFO:(state,info)=>{
            state.info=info
        }
    },
    actions: {
        // 异步任务都建议在此进行，包括登陆，如果需要共享的请求，也建议在此
        Login({commit},userinfo){
            return new Promise((resolve,reject)=>{
            
                login(userinfo).then(res=>{
                    // 判断登陆是否成功，成功后将数据传入vuex,失败也将结果传入后续中
                    resolve(res)
                })
            })
        }
    }

}
export default user 
